package br.ufal.questione.domain;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(schema = "questione", name = "questionario")
public class Questionario implements Serializable {

	private static final long serialVersionUID = 5588870729969700276L;

	@Id
	@SequenceGenerator(name = "sequence-generator", sequenceName = "questione.questionario_ID_seq", allocationSize = 1)
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequence-generator")
	@Column(name = "id")
	private Long id;

	@Column(name = "descricao")
	private String descricao;
	
	@Temporal(TemporalType.DATE)
	@Column(name = "data_inicio")
	private Date dataInicio;
	
	@Temporal(TemporalType.DATE)
	@Column(name = "data_fim")
	private Date dataFim;
	
	@Column(name = "liberado")
	private Boolean liberado;
	
	@ManyToOne
	@JoinColumn(name = "id_curso")
	private Curso curso;
	
	@Column(name = "tipo_questionario")
	@Enumerated(EnumType.STRING)
	private TipoQuestionario tipoQuestionario;
		
	@OrderBy("ordem")
	@OneToMany(mappedBy = "questionario", cascade = CascadeType.ALL)
	private Set<Pergunta> perguntas = new HashSet<Pergunta>();
	
	@OneToMany(mappedBy = "questionario", cascade = CascadeType.ALL)
	private Set<Avaliacao> avaliacoes = new HashSet<Avaliacao>();

	public Questionario() {
		super();
	}

	public Questionario(Long id) {
		super();
		this.id = id;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Set<Pergunta> getPerguntas() {
		return perguntas;
	}

	public void setPerguntas(Set<Pergunta> perguntas) {
		this.perguntas = perguntas;
	}

	public String getDescricao() {
		return descricao;
	}

	public void setDescricao(String descricao) {
		this.descricao = descricao;
	}

	public TipoQuestionario getTipoQuestionario() {
		return tipoQuestionario;
	}

	public void setTipoQuestionario(TipoQuestionario tipoQuestionario) {
		this.tipoQuestionario = tipoQuestionario;
	}
	public Date getDataInicio() {
		return dataInicio;
	}

	public void setDataInicio(Date dataInicio) {
		this.dataInicio = dataInicio;
	}

	public Date getDataFim() {
		return dataFim;
	}

	public void setDataFim(Date dataFim) {
		this.dataFim = dataFim;
	}

	public void setAvaliacoes(Set<Avaliacao> avaliacoes) {
		this.avaliacoes = avaliacoes;
	}

	public Set<Avaliacao> getAvaliacoes() {
		return avaliacoes;
	}

	public void setLiberado(Boolean liberado) {
		this.liberado = liberado;
	}

	public Boolean getLiberado() {
		return liberado;
	}
	
}
